﻿using Common;
using DB.MongoDB.Model;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DB.MongoDB
{
     

    public interface IMongoDbHelper<TEntity> where TEntity : IEntity<ObjectId>
    {
         
        /// <summary>
        /// 单个插入
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TEntity> Insert(TEntity entity);
        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<TEntity[]> Insert(TEntity[] entity);
        /// <summary>
        /// 根据ID  Update一个字段
        /// </summary>
        /// <param name="id"></param>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        Task<bool> Modify(string id, string field, string value);
        Task<bool> Update(TEntity entity);
        /// <summary>
        /// 根据查询条件Update
        /// </summary>
        /// <param name="filterGroup"></param>
        /// <param name="setfield"></param>
        /// <returns></returns>
        Task<bool> UpdateManyAsync(FilterGroup filterGroup, Dictionary<string, string> setfield);
        /// <summary>
        /// 删除具体实例
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task<bool> Delete(TEntity entity);
        /// <summary>
        /// 根据ID删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> Delete(string id);
        /// <summary>
        /// 根据查询条件删除
        /// </summary>
        /// <param name="filterGroup"></param>
        /// <returns></returns>
        Task<bool> Delete(FilterGroup filterGroup);
        /// <summary>
        /// 根据ID查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TEntity> QueryOne(string id);
        /// <summary>
        /// 返回IQueryable对象
        /// </summary>
        /// <returns></returns>
        IMongoQueryable<TEntity> AsQueryable();
        /// <summary>
        /// 根据查询条件返回List对象
        /// </summary>
        /// <param name="filterGroup"></param>
        /// <returns></returns>
        Task<List<TEntity>> QueryFilter(FilterGroup filterGroup);
    }
}
